#include <stdio.h>
char buffer[2048];
int version = 1;
void copy(int old,int new)
{
  int count;
  while((count = read(old,buffer,sizeof(buffer)))>0)
    write(new,buffer,count);
}


int main(int argc,char **argv)
{
  int fdold,fdnew;
  if (argc != 3) {
    printf("need 2 arguments for copy!!!");
    return 1;
  }

  fdold = open(argv[1],0111);
  if (fdold == -1) {
    printf("cannot open file %s\n",argv[1]);
    return 1;
  }

  fdnew = create(argv[2],0666);
  if (fdnew == -1) {
    printf("cannot create file %s\n",argv[2]);
    return 1;
  }

  copy(fdold,fdnew);
  return 0;
}

